var form,$,table,layer,upload,node;
var user = JSON.parse(localStorage.getItem("user"));
var userId = user.userId;
layui.use(['form','jquery','table','layer','upload'],function() {
    form = layui.form;
    $ = layui.jquery;
    table = layui.table;
    layer = layui.layer;
    upload = layui.upload;
    //展示树节点
    getJsActicleCategroy();
})
//获取微圈分类树信息
function getJsActicleCategroy() {
    $.ajax({
        url:'/microcircle/getJsActicleCategroy',
        type: "post",
        dataType:'json',
        data: {},
        success:function (data) {
            showZtree(data.data);
        }
    });
}
//展示微圈分类树
function showZtree(data) {
    //ztree树配置
    var setting = {
        data:{
            simpleData: {
                enable: true,
                idKey: "acticleCategroyId",
                pIdKey: "parentId",
                rootPId: -1
            },
            key: {
                name: "artcleCategroyName"
            }
        },
        check: {
            enable: true,
            chkStyle: "checkbox",
        },
        view:{
            showLine: true,
            showIcon:false,
        },
        callback:{
            //点击前回调
            beforeCheck : function zTreeBeforeClick(treeId, treeNode, clickFlag) {
                var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                zTree.checkAllNodes(false);
                return !treeNode.isParent;//当是父节点 返回false 不让选取
            },
            //点击回调
            onCheck: choose, //点击选择分类
        }
    };
    function choose(event,treeId,treeNode){
        //父窗口赋值
        parent.$("input[name=acticleCategroyId]").val(treeNode.acticleCategroyId);
        parent.$("input[name=artcleCategroyName]").val(treeNode.artcleCategroyName);
        $("input[name=acticleCategroyId]").val(treeNode.acticleCategroyId);
        $("input[name=artcleCategroyName]").val(treeNode.artcleCategroyName);
    }
    //初始化ztree
    zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, data );
    zTreeObj.expandAll(true);//展开全部节点
    //节点回显（默认显示）
    if ($("input[name=acticleCategroyId]",window.parent.document).val()) {
        var node = zTreeObj.getNodeByParam("acticleCategroyId",$("input[name=acticleCategroyId]",window.parent.document).val(),null);
        zTreeObj.checkNode(node,true,true);
    }
}
//取消——关闭窗口
$("#cancel").on("click",function () {
    var layer = parent.layer;
    layer.close(layer.index);
});
//确定
$("#sub").on("click",function () {
    var acticleCategroyId = $("input[name=acticleCategroyId]").val();
    var artcleCategroyName = $("input[name=artcleCategroyName]").val();
    parent.$("input[name=acticleCategroyId]").val(acticleCategroyId);
    parent.$("input[name=artcleCategroyName]").val(artcleCategroyName);
    var layer = parent.layer;
    layer.close(layer.index);
});